<?php
namespace app\tripapi\model;
use think\Model;
use think\Db;
class ApprovalProces extends Model{
    /*
     * 初始化
     */
    public function __construct(){
        parent::__construct();
    }
    /*
     * 保存审批流
     */
    public function CustomerSave($params){
        $data['department_name'] = iconv('UTF-8', 'GBK', $params['department_name']);
        $data['step1'] = iconv('UTF-8', 'GBK', $params['step1']); // 部门审批
        $data['step2'] = iconv('UTF-8', 'GBK', $params['step2']); // 总经理审批
        if(!empty($params['step3'])){
            $data['step3'] = iconv('UTF-8', 'GBK', $params['step3']); // 洽谈单需要 -- 行政审批
        }
        if(!empty($params['step4'])){
            $data['step4'] = iconv('UTF-8', 'GBK', $params['step4']); // 洽谈单需要 -- 若需要财务审批 则进行财务审批
        }
        $result = Db::name('approval_proces')->insert($data, false, true);
        return $result;
    }
    /*
     * 更新审批流
     */
    public function CustomerUpdate($params){
        $data['department_name'] = iconv('UTF-8', 'GBK', $params['department_name']);
        $data['step1'] = iconv('UTF-8', 'GBK', $params['step1']); // 部门审批
        $data['step2'] = iconv('UTF-8', 'GBK', $params['step2']); // 总经理审批
        if(!empty($params['step3'])){
            $data['step3'] = iconv('UTF-8', 'GBK', $params['step3']); // 洽谈单需要 -- 行政审批
        }
        if(!empty($params['step4'])){
            $data['step4'] = iconv('UTF-8', 'GBK', $params['step4']); // 洽谈单需要 -- 若需要财务审批 则进行财务审批
        }
        Db::name('approval_proces')->where('id', '=', $params['editid'])->update($data);
        return true;
    }
    /*
     * 获取审批流列表
     */
    public function GetList(){
        $result = Db::name('approval_proces')->select();
        foreach($result as $key => $value){
            $result[$key]['department_name'] = iconv('GBK', 'UTF-8', $value['department_name']);
            $result[$key]['step1'] = iconv('GBK', 'UTF-8', $value['step1']); // 部门审批
            $result[$key]['step2'] = iconv('GBK', 'UTF-8', $value['step2']); // 总经理审批
            if(isset($value['step3'])){
//                echo "123";exit;
                $result[$key]['step3'] = iconv('GBK', 'UTF-8', $value['step3']); // 洽谈单需要 -- 行政审批
            }
            if(isset($value['step4'])){
//                echo "456";exit;
                $result[$key]['step4'] = iconv('GBK', 'UTF-8', $value['step4']); // 洽谈单需要 -- 若需要财务审批 则进行财务审批
            }
        }
        return $result;
    }
    /*
     * 根据id获取详情
     */
    public function GetDetailById($id){
        $result = Db::name('approval_proces')->where('id' ,'=', $id)->select();
        foreach($result as $key => $value){
            $result[$key]['department_name'] = iconv('GBK', 'UTF-8', $value['department_name']);
            $result[$key]['step1'] = iconv('GBK', 'UTF-8', $value['step1']); // 部门审批
            $result[$key]['step2'] = iconv('GBK', 'UTF-8', $value['step2']); // 总经理审批
            if(!empty($value['step3'])){
                $result[$key]['step3'] = iconv('GBK', 'UTF-8', $value['step3']); // 洽谈单需要 -- 行政审批
            }
            if(!empty($value['step4'])){
                $result[$key]['step4'] = iconv('GBK', 'UTF-8', $value['step4']); // 洽谈单需要 -- 若需要财务审批 则进行财务审批
            }
        }
        return $result;
    }
}

?>